package com.cskaoyan.service;

import com.cskaoyan.bean.MarketGoodsSpecification;
import com.cskaoyan.bean.MarketGoodsSpecificationExample;
import com.cskaoyan.mapper.MarketGoodsSpecificationMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.TransactionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月30日 13:48
 */
public class GoodsSpecificationServiceimpl implements GoodsSpecificationService {
    @Override
    public void add(MarketGoodsSpecification specification) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsSpecificationMapper mapper = sqlSession.getMapper(MarketGoodsSpecificationMapper.class);
        mapper.insertSelective(specification);
    }

    @Override
    public List<MarketGoodsSpecification> selectByGoodsId(Integer id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketGoodsSpecificationMapper mapper = sqlSession.getMapper(MarketGoodsSpecificationMapper.class);
        MarketGoodsSpecificationExample example = new MarketGoodsSpecificationExample();
        MarketGoodsSpecificationExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        List<MarketGoodsSpecification> specificationList = mapper.selectByExample(example);
        return specificationList;
    }

    @Override
    public void update(MarketGoodsSpecification specification) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsSpecificationMapper mapper = sqlSession.getMapper(MarketGoodsSpecificationMapper.class);
        mapper.updateByPrimaryKeySelective(specification);
    }
}
